angular.module("crawlerApp").controller("taskResultCtrl",function($scope,$http,$state,$stateParams){
    $scope.page= 0;
    $scope.task=$stateParams.config;
    getDataByRuleId();
    function getDataByRuleId(){
        var param = {
            "query": {
                "match": {
                    "ruleId": $scope.task.id
                }
            },
            "size": 10,
            "from": 10 * $scope.page,
        };
     /*   var json={
            data: $scope.task.id,
            page:$scope.page
        };*/
        $http.post("crawler/task/get",param).then(function (response) {
           // $scope.pageContents=response.data.content;
            //$scope.currentPage=response.data.number;
            //$scope.totalPage=response.data.totalPages;
           // $scope.totalCount=response.data.totalElements;
            $scope.pageContents = response.data.data;
            $scope.totalCount = response.data.total;
            if (Number(response.data.total) % 10 == 0) {
                $scope.totalPage = Number(response.data.total) / 10;
            } else {
                $scope.totalPage = Math.ceil(response.data.total / 10);
            }
        })
    }
    $scope.Previous=function (page) {
        if(page-1>=0){
            $scope.page=page-1;
        }
        getDataByRuleId()
    };

    $scope.Next=function(page){
        if(page+1<=$scope.totalPage-1){
            $scope.page=page+1;
        }
        getDataByRuleId();
    };

    $scope.goto=function (page) {
        if(Number(page)<=$scope.totalPage&&Number(page)>0){
            $scope.page=Number(page)-1;
        }
        getDataByRuleId();
    };

    var E, editor;
    E = window.wangEditor;
    editor = new E('#editor'); //id一定要一致
    editor.customConfig.menus = [
        'head',  // 标题
        'bold',  // 粗体
        'fontSize',  // 字号
        'fontName',  // 字体
        'italic',  // 斜体
        'underline',  // 下划线
        'foreColor',  // 文字颜色
        'backColor',  // 背景颜色
        'link',  // 插入链接
        'list',  // 列表
        'justify',  // 对齐方式
        'image',  // 插入图片
        'table',  // 表格
        'video',  // 插入视频
        'code',  // 插入代码
        'undo'  // 撤销
    ];
    //如果需要使用 base64 编码直接将图片插入到内容中，可参考一下示例配置
    editor.customConfig.uploadImgShowBase64 = true;
    // 将图片大小限制为 10M
    editor.customConfig.uploadImgMaxSize = 10* 1024 * 1024;
    //创建editor
    editor.create();
    //设置内容不可编辑
    editor.$textElem.attr('contenteditable', false);
    //获取内容的方式
  //editor.txt.text()
  $scope.editorContent=function(pageContent){
      editor.txt.html( pageContent.content);
  };
    $scope.editorTitle=function(pageContent){
        editor.txt.html( pageContent.title);
    };
    $scope.editorData=function(pageContent){
        editor.txt.html( pageContent.dataItem);

    };

});
